package com.erclab.internal.xpresso.formelements;

import java.util.Properties;

import com.erclab.internal.xpresso.exceptions.FormException;
import com.erclab.internal.xpresso.forms.Form;

public class SimplePassword extends SimpleInputBox {

	public SimplePassword(){
		
	}
	
	public String toHTML(Form theForm) {
		StringBuffer sb = new StringBuffer();
		sb.append("<INPUT TYPE=\"password\" name=\"Field");
		sb.append(this.idFormElement);
		sb.append("\" id=\"" + this.destinationColumn  + "\" ");
		if (theForm.getFormParameters().getAction().equals("update")){
			if(originalValue != null){
				sb.append("value=\"" + originalValue + "\" ");
			}
		}
		sb.append(">");
		
		
		Properties params = this.getElementParameters();
		if (params != null && params.getProperty("password.confirm.column") != null){
			sb.append("<input type=\"hidden\" id=\"pccol\" value=\"Confirm" + params.getProperty("password.confirm.column") + "\">\n" +
					"<input type=\"hidden\" id=\"cPass\" value=\"true\">" 
					+ "<input type=\"hidden\" id=\"confirmPasswordMessage\" value=\"" + params.getProperty("password.confirm.message") + "\">");
		} else {
			sb.append("<input type=\"hidden\" id=\"cPass\" value=\"false\">");
		}
		return sb.toString();

	}

	public void loadLookupValues(Form theForm) throws FormException {
		// Not necessary for password element
	}

	public boolean isModifiable() {
		return true;
	}

}
